<template>
  <div class="table">
    <el-table
      :data="tableData"
      :loading="loading"
      @selection-change="handleSelectionChange"
      style="width: 100%"
      :header-cell-style="{
        background: '#F1F1F1',
        'font-size': '14px',
        'font-weight': 600,
        color: '#333333',
      }"
      :cell-style="{
        'font-size': '14px',
        'font-weight': 400,
        color: '#333333',
      }"
    >
      <el-table-column type="selection" width="55" fixed="left" />
      <el-table-column label="序号" min-width="60" fixed="left">
        <template #default="scope">
          {{ (scope.$index + 1).toString().padStart(2, "0") }}
        </template>
      </el-table-column>
      <el-table-column prop="sensingModeName" label="感知模式" min-width="120" />
      <el-table-column prop="deviceCode" label="设备编号" min-width="120" />
      <!-- <el-table-column prop="region" label="归属行政区" min-width="100" /> -->
      <el-table-column prop="section" label="归属路段" min-width="100" />
      <el-table-column prop="berthCodeStr" label="关联泊位编号" min-width="130" />
      <el-table-column prop="createdTime" label="操作时间" min-width="180" />
      <el-table-column label="操作" width="90" fixed="right">
        <template #default="scope">
          <el-button
            @click="associatedBerthData(scope.row)"
            type="primary"
            size="small"
            link
            style="color: #007aff; font-size: 14px"
          >
            关联泊位</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { reactive, ref, defineProps } from "vue";
const imgNone = new URL("@/assets/image/imgNone.png", import.meta.url).href;
const emits = defineEmits(["table"]);

const props = defineProps({
  tableData: {
    type: Object,
    default: () => {},
  },
  loading: {
    type: Boolean,
    default: false,
  },
});

// 关联泊位
const associatedBerthData = (row) => {
  row.operation = 1;
  emits("table", row);
};

const bingModeNameList = ref([]);
const bingCodeList = ref([]);

const handleSelectionChange = (val) => {
  console.log("val ===>", val);

  let row = {};
  row.operation = 2;
  bingModeNameList.value = val.map((proxy) => proxy.sensingModeName);
  bingCodeList.value = val.map((proxy) => proxy.deviceCode);
  row.bingModeNameList = bingModeNameList.value;
  row.bingCodeList = bingCodeList.value;
  emits("table", row);
};
</script>

<style lang="less" scoped>
.table {
  margin-bottom: 15px;
}
</style>
